home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / contrib / partingr / mm2mx64 < prev    next >
Text File  |  1995-02-24  |  5KB  |  174 lines

  1. #!/usr/common/bin/perl
  2. do "getopts.pl" || die "$!";
  3. do Getopts('imnd:l:');
  4.  
  5. do "TeXthings";
  6.  
  7. $sectionref='a'; $i=0;
  8. if($opt_l)
  9.  { open(LOGFILE,">$opt_l") || die "$!"; }
  10.   
  11. while(<>)
  12. {
  13. #  s/\n$//;
  14.   s/^@//;
  15. # expand wildcard references here, then process as normal
  16.   if(/^(use|defn) (.*)\.{3}$/)
  17.     { print LOGFILE "Wildcard `$2...', expands to  " if $opt_l;
  18.       @matches=grep(/^$2.*/i,split(/ñ/,$known));
  19.       if($#matches>0)
  20.         { 
  21.           print LOGFILE "[",join('][',@matches),"] " if $opt_l;
  22.           print STDERR "Ambiguous module name `$mod...', line $i\n";
  23.           print STDERR "Matches: [",join('][',@matches),"]\n";
  24.           print STDERR "Using `",@matches[0],"'\n";
  25.           #die "\nAmbiguous module name `$mod...', line $i"; 
  26.         }
  27.       elsif($#matches==-1)
  28.         { 
  29.           die "\nNo match for name `$mod...', line $i";
  30.         }
  31.       $mn=@matches[0];
  32.       if($mn=~/\[\[/) { $mn=&convquotes($mn); }
  33.       print LOGFILE $mn,"\n" if $opt_l;
  34.       $_="$1 $mn";
  35.     }
  36.  
  37. # process a <<defn>>=
  38.   if(/^defn (.*)$/)
  39.     { print LOGFILE "Defining chunk `$1' with macro $sectionref\n" if $opt_l;
  40.       $md=$1; $mn=$1; if($opt_n) { $md=~tr/A-Z/a-z/; }
  41.       $mt=$md;
  42.       $mt=~s/([*+.?{}()])/\\\1/g;
  43.       if($known!~/ñ$mt/) { $known=$known . "ñ$md"; }
  44.       @names{$md}=1; $currentmod=$md;
  45.       @defines{$md}=@defines{$md} . "\\\\{\\xp\\z$sectionref}";
  46.       #if($mn=~/\[\[/) { $mn=&convquotes($mn); }
  47.       @lines[$i]="defn z$sectionref $mn\n"; $oldref=$sectionref;
  48.       $sectionref++;
  49.       push(@uses,$i);
  50.       $indxing=0;
  51.     }
  52. # process a <<use>>
  53.   elsif(/^use (.*)$/)
  54.     { print LOGFILE "Using chunk `$1' in chunk $oldref\n" if $opt_l;
  55.       $md=$1; $mn=$1; if($opt_n) { $md=~tr/A-Z/a-z/; }
  56.       $mt=$md;
  57.       $mt=~s/([*+.?{}()])/\\\1/g;
  58.       if($known!~/ñ$mt/) { $known=$known . "ñ$md"; }
  59.       @reference{$md}=@reference{$md} . "\\\\{\\xp\\z$oldref}";
  60.       #if($mn=~/\[\[/) { $mn=&convquotes($mn); }
  61.       @lines[$i]="use z$oldref $mn\n";
  62.       push(@uses,$i); 
  63.       $indxing=0;
  64.     }
  65. # process identifier information
  66.   elsif(/^index (nl|defn |use )(.*)/)
  67.     {  
  68.       if($2 eq '|') { $indxing=1; }
  69.       else
  70.       { if($2)
  71.         { print LOGFILE "Identifier `$2' indexed as " if $opt_l;
  72.           if($1 eq "defn " && !$indxing)
  73.            { print LOGFILE "defined [$oldref]\n" if $opt_l;
  74.              $style="";
  75.            }
  76.           else
  77.            { print LOGFILE "used [$oldref]\n" if $opt_l;
  78.              $style="\\it";
  79.            }
  80.           @variables{$2}=@variables{$2} . ",\\thinspace{$style\\xp\\z$oldref}";
  81.         }
  82.       }
  83.       $i--; # don't put this line in the file here
  84.     }
  85. # stick the line in the array
  86.   else { @lines[$i]=$_; }
  87.   $i++;
  88. }
  89.  
  90. if($opt_l)
  91.  {
  92.    print LOGFILE "\n\nList of modules currently defined\n";
  93.    print LOGFILE join("\n",sort keys(defines));
  94.    print LOGFILE "\n\nList of modules currently referenced\n";
  95.    print LOGFILE join("\n",sort keys(reference));
  96.    print LOGFILE "\n\n";
  97.  }
  98.  
  99. foreach(keys(reference))
  100.  { @longlist{$_}=@reference{$_}; }
  101.  
  102. foreach(keys(defines))
  103.  { @longlist{$_}=@longlist{$_} . ('%' . @defines{$_}); }
  104.  
  105. foreach(@uses)
  106.  { 
  107.    $ref=@lines[$_];
  108.    $ref=~/^(use|defn) (z[a-z]+) (.*)/;
  109.    $mn=$3; $dr=$2; $ac=$1;
  110.    $defns=@defines{$mn};
  111.    print LOGFILE "Module $mn " if $opt_l;
  112.    if($ac eq 'defn')
  113.     { $uses=@reference{$mn}; $uses="{$uses}|";
  114.       print LOGFILE "defined at line $_, $uses\n" if $opt_l;
  115.     }
  116.    else
  117.     { $uses=''; 
  118.       print LOGFILE "referenced at line $_\n" if $opt_l;
  119.     }
  120.    print LOGFILE "Line $_ modified to `$ac $dr {$defns} $uses$mn'\n" if $opt_l;
  121.    $mn=&convquotes($mn);
  122.    @lines[$_]="$ac $dr|{$defns}|$uses $mn\n";
  123.  }
  124.         
  125. print STDOUT "header tex \n",@lines;
  126.  
  127. # now @longlist{MOD} contains a list of all the references to <MOD>
  128. # sort them to make them look pretty
  129.  
  130. if($opt_m)
  131.   {
  132.     print LOGFILE "Making module index...\n" if $opt_l;
  133.     print "index mods\n";
  134.     foreach(sort keys(longlist))
  135.       {
  136.         $defns=@defines{$_};
  137.         $defns=~s/^,\\\\thinspace//;
  138.         print LOGFILE "Module <$_ $defns> ",@reference{$_},"\n" if $opt_l;
  139.        # first we print the module name and defining numbers
  140.         print "entry {\\LA ",&convquotes($_),"\\ \\xwp{$defns}\\RA}\\quad";
  141.        # now we print the bit after that : assume foot=cmr8
  142.         print "{\\foot\\xtc{",@reference{$_},"}}\n";
  143.       }
  144.     print "end index\n";
  145.   }
  146.  
  147. if($opt_i)
  148.   {
  149.     print "index ids\n";
  150.     foreach(sort keys(variables))
  151.      {
  152.         $vars=@variables{$_};
  153.         $vars=~s/^,\\thinspace//;
  154.         print "entry {\\code ",&TeXliteral($_),"\\edoc} :\\quad",$vars,"\n";
  155.       }
  156.     print "end index\n";
  157.   }
  158.   
  159. print STDOUT "trailer tex\n";
  160.  
  161. sub usage_info
  162. {
  163.   local($line)=@_;
  164.   @ixrefs=sort(split(/%/,@reference{$line}));
  165.   if($#ixrefs==-1)
  166.     { return "This code is never referenced. It may be a root module.";}
  167.   elsif($#ixrefs==0)
  168.     { return "This code is used in section ",@ixrefs[0]; }
  169.   else
  170.     { $lastref=pop(@ixrefs);
  171.       return "This code is used in sections ",join(",\\,",@ixrefs)," and $lastref";
  172.     }
  173. }
  174.